import { _decorator, sys } from 'cc';
import { GameTip } from '../Managers/TipMgr';
import { BaseClass } from '../Managers/BaseClass';
import { Platform } from '../Platform/PlatformWX';
import { WECHAT } from 'cc/env';
const { ccclass, property } = _decorator;

@ccclass('NativeMgr')
export class NativeMgr extends BaseClass {
    
    private static _inst: NativeMgr;
    public static get inst(): NativeMgr {
        if (this._inst == null) {
            this._inst = new NativeMgr();
        }
        return this._inst;
    }

    constructor() {
        super()    
        this.Init();
    }


    public Init(){
        // sda 
    }

    public capyToClipBoard(str: string){
        if(sys.platform === sys.Platform.WECHAT_GAME){
            Platform.inst.capyToClipBoard(str);
        }else if(sys.isNative){
            //原生自己实现
        }else if(sys.isBrowser){
            console.log('=====capyToClipBoard 浏览器平台复制========')
            var textarea = document.createElement('textarea');
            textarea.textContent = str;
            document.body.appendChild(textarea);
            textarea.readOnly = true;
            textarea.select();
            textarea.setSelectionRange(0,textarea.textContent.length);
            try {
                const flag = document.execCommand('copy');
                document.body.removeChild(textarea);
                if(flag){
                    console.log('复制数据成功！');
                    GameTip.inst.showTip("复制数据成功！");
                    return true;
                }else{
                    console.log('复制失败！');
                    GameTip.inst.showTip("复制失败！");
                    return false;
                }
            } catch (error) {
                console.log('复制失败！');
                GameTip.inst.showTip("复制失败！");
                return false;
            }
        }
    }

    //挑战成功和失败分享
    public shareSuccess(): void{
        console.log('======挑战成功分享=========');

        GameTip.inst.showTip('挑战成功分享，开发中');
    }

    //观看视屏获得挑战机会
    public seeView(calBack: Function){
        if(WECHAT){
            
        }else{
            GameTip.inst.showTip('当前不是微信环境！');
            calBack && calBack();
        }
    }
}


